package service.impl;

import dao.ManagerDao;
import dao.StudentDao;
import moudle.Student;
import org.apache.ibatis.session.SqlSession;
import service.StudentService;
import tools.Dbutils;

import java.util.List;

public class StudentImplService implements StudentService {
    SqlSession sqlSession = Dbutils.getSqlSession();
//    渲染数据
    @Override
    public List<Student> getAllService() {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        List<Student> allDao = mapper.getAllDao();
        return allDao;
    }

    @Override
    public Boolean isAdminService(String admin,String Password) {
        ManagerDao mapper = sqlSession.getMapper(ManagerDao.class);
        Boolean adminDao = mapper.isAdminDao(admin, Password);
        return adminDao;
    }

    @Override
    public int delService(Integer id) {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        int i = mapper.delDao(id);
        sqlSession.commit();//点击删除实际没有删除，是因为没有提交事务
        return i;
    }

    @Override
    public int insertService(Student student) {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        int i = mapper.insertDao(student);
        sqlSession.commit();
        return i;
    }

    @Override
    public Student getOneService(Integer id) {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        Student stu = mapper.getOneDao(id);
        sqlSession.commit();
        return stu;
    }

    @Override
    public int updateService(Student student) {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        int i = mapper.updateDao(student);
        sqlSession.commit();
        return i;
    }

    @Override
    public List<Student> fenYeService(Integer start, Integer pageSize) {
        StudentDao mapper = sqlSession.getMapper(StudentDao.class);
        List<Student> allDao = mapper.fenYeDao(start, pageSize);
        return allDao;
    }
}
